<template>
	<view class="container">
		<view class="header">
			<u-swiper :list="list" bg-color="#fff"></u-swiper>
			<u-notice-bar mode="horizontal" :list="notice"></u-notice-bar>
		</view>
		<view class="main">
			<view class="main-title">
				<u-row justify="center">
					<u-col span="4">
						<view class="trad-data">
							<view>{{usMoney}}</view>
							<view>今日聚合收款（元1）</view>
						</view>
					</u-col>
					<u-col span="4">
						<view class="trad-data">
							<view>{{onlineMoney}}</view>
							<view>今日线上收款（元）</view>
						</view>
					</u-col>
					<u-col span="4">
						<view class="trad-data">
							<view>{{count}}</view>
							<view>今日交易总数（条）</view>
						</view>
					</u-col>
				</u-row>
			</view>
			<view class="main-item">
				<u-section title="商户功能" :right="false"></u-section>
				<view class="btn-group">
					<u-grid :col="3" :border="false">
						<u-grid-item @click="order">
							<u-icon name="order" :size="46" color="#f29100"></u-icon>
							<view class="grid-text">订单列表</view>
						</u-grid-item>
						<u-grid-item @click="bindpush">
							<u-icon name="account" :size="46" color="#2b85e4"></u-icon>
							<view class="grid-text">绑定公众推送</view>
						</u-grid-item>
						<u-grid-item @click="cancelpush">
							<u-icon name="account" :size="46" color="#2b85e4"></u-icon>
							<view class="grid-text">解绑推送</view>
						</u-grid-item>
						<u-grid-item @click="passwordUp">
							<u-icon name="account" :size="46" color="#2b85e4"></u-icon>
							<view class="grid-text">修改密码</view>
						</u-grid-item>
						<u-grid-item @click="logout">
							<u-icon name="fingerprint" :size="46" color="#2b85e4"></u-icon>
							<view class="grid-text">退出</view>
						</u-grid-item>
					</u-grid>
				</view>
			</view>
		</view>
		<view>
				<u-popup v-model="show"  mode="center" width="80%" height="30%" border-radius="14">
					<view style="display: flex;flex-direction: column;align-items: center;">
						<view style="display: flex;height: 3rem;line-height: 3rem;margin-top: 3rem;">
							<view>新密码：</view>
							<u-input v-model="password" type="password" placeholder="请输入密码" :focus='focus' height="100" :border="border" style="height: 3rem;width: 10rem;"/>
						</view>
						<u-button type="primary" style="margin-top: 2rem;" @click="password()">主要按钮</u-button>
					</view>

				</u-popup>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				list: [{
						image: 'https://qiniu.hiima.cn/9b20c26376a9301fa0242a07b8a25c24857ea3481619424484.jpg',
						title: '招商'
					},
					{
						image: 'https://qiniu.hiima.cn/344333f587b9156ee7be8ffef20499fc11c4943f1619424512.jpg',
						title: '招商'
					},
				],
				notice: [
					'全国各地区招商',
					'火热进行中',
				],
				show: false,
				password:'',
				border: true,
				focus: true,
				count: 0,
				onlineMoney: 0,
				usMoney: 0,
			}
		},
		onLoad(option) {
			if (option.type) { //绑定微信推送成功
				if (option.type == 200) {
					uni.showToast({
						title: option.msg,
						icon: 'success',
						duration: 2000
					});
				} else {
					uni.showToast({
						title: option.msg,
						icon: 'error',
						duration: 2000
					});
				}
			}
			//获取首页统计
			let that = this;
			this.$request.httpTokenRequest({
				url: '/admin/statistical/mobileCount',
				method: 'POST',
				data: {
					rule: uni.getStorageSync('role'),
					userID: uni.getStorageSync('userID'),
				},
				// needToken: false,
			}).then(res => {
				if (res.data.code == 200) {
					that.count = res.data.content.count;
					that.onlineMoney = res.data.content.onlineMoney;
					that.usMoney = res.data.content.usMoney;
				}
			}, error => {

			});
		},
		methods: {
			//微信公众号授权,绑定推送
			bindpush() {
				let appid = 'wxd8978cc4068bc70c';
				let uri = 'https://openpay.duolaibei.com/mobile/push/getCode?userID=' + uni.getStorageSync('userID');
				let authURL =
					`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_base&state=1#wechat_redirect`;
				window.location.href = authURL;
			},
			cancelpush() {
				let appid = 'wxd8978cc4068bc70c';
				let uri = 'https://openpay.duolaibei.com/mobile/push/getCode?userID=' + uni.getStorageSync('userID');
				let authURL =
					`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_base&state=2#wechat_redirect`;
				window.location.href = authURL;
			},
			//订单页
			order() {
				uni.navigateTo({
					url: '/pages/order-list/index'
				});
			},
			//退出登录
			logout() {
				var token = uni.getStorageSync('token');
				let that = this;
				this.$request.httpTokenRequest({
					url: '/admin/login/loginOut',
					method: 'POST',
					data: {
						token: token
					},
					// needToken: false,
				}).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: '退出成功',
							icon: 'success',
							duration: 2000
						});
						uni.clearStorageSync();
						var timer = setTimeout(() => {
							uni.reLaunch({
								url: '/pages/login/login'
							});
							timer = null
						}, 1000);
					} else {
						uni.showToast({
							title: res.data.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}, error => {

				});
			},
			//修改密码
			passwordUp(){
				console.log(1)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding-bottom: 1rem;

		.header {
			// margin-top: 20rpx;
		}
	}

	.main {
		.main-title {
			width: 100%;
			padding: .5rem 0;
			border-bottom: .01rem solid $u-type-info-disabled;

			.trad-data {
				text-align: center;

				view:first-child {
					font-size: .8rem;
					line-height: 1.3rem;
					font-weight: 600;
				}
			}
		}

		.main-item {
			width: 96%;
			margin: .6rem auto 0 auto;
			// margin-top: .6rem;

			.btn-group {
				width: 90%;
				margin: .6rem auto 0 auto;

				navigator {
					text-align: center;

					.grid-text {
						font-size: .5rem;
						line-height: 1.5rem;
					}
				}
			}
		}

	}
</style>
